define(function(){
	function login(){
		var phonenum = $(".login_phone input");
		var ver = $(".login_ver input");
		var code = $(".phone_code");
		var pass = $(".login_password input");
		var repass = $(".login_repassword input");
		var vernum = $(".login_ver b");
		var verd = ""
		for(var i = 0;i<4 ; i++){
			verd+= Math.floor(Math.random()*10);			
		}
		vernum.html(verd);
		phonenum.blur(function(){
			var phone = phonenum.val();
			var re = /^1[0-9]{10}$/;
			if(re.test(phone)){
				$(".login_phone").css("background","url(img/right.jpg) no-repeat right center");
				$(".login_phone b").css("display","none");
			}else{
				$(".login_phone b").css("display","block");
			}
		})
		ver.blur(function(){
			var ve = $(".login_ver input").val();
			if(verd == ve){
				$(".login_ver").css("background","url(img/right.jpg) no-repeat right top");
				$(".login_ver em").css("display","none");
			}else{
				$(".login_ver em").css("display","block");
			}
		})
		code.blur(function(){
			var re = /^[0-9]{4}$/
			var phonecode = code.val();
			if(re.test(phonecode)){
				$(".login_phone_ver").css("background","url(img/right.jpg) no-repeat 300px center");
				$(".login_phone_ver b").css("display","none");
			}else{
				$(".login_phone_ver b").css("display","block");
			}
		})
		pass.blur(function(){
			var re = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,20}$/;
			var passval = pass.val();
			if(re.test(passval)){
				$(".login_password").css("background","url(img/right.jpg) no-repeat right center");
				$(".login_password b").css("display","none");
			}else{
				$(".login_password b").css("display","block");
			}
		})
		repass.blur(function(){
			if(pass.val() == repass.val() && repass.val() !==""){
				$(".login_repassword").css("background","url(img/right.jpg) no-repeat right center");
				$(".login_repassword b").css("display","none");
			}else{
				$(".login_repassword b").css("display","block");
			}
		})
		if(phonenum !== ""&& ver!=="" && code !=="" && pass!== ""&&repass !== ""){
			$(".login_zc").click(function(){
				var user = phonenum.val();
				var pas = pass.val();
				var _key = "user";
				var _value = '{"name":'+user+',"pass":"'+pas+'"}';
				$.cookie(_key,_value,{expires:7,path:"/"});
				window.location ="log.html" ;
			})
		}
	} 
	function log(){
		var _key = "user";
		var value = $.cookie(_key);
		if(value){
			var use = JSON.parse(value);
			$(".user").val(use.name);
			$(".password").val(use.pass);
			$(".log_dl").click(function(){
			window.location ="index.html"
		}) 
		}
	}
	return{
		login:login,
		log:log
	}
})